#include "clkTimer.h"

clkTimer::clkTimer()
{
	m_tmrFirst = true;

	m_tmrFrequency = 0;
	m_tmrStart = 0;
	m_tmrTicks = 0;
	m_tmrTime = 0;
	m_tmrPrevious = 0;
	m_tmrElapsed = 0;

	m_tmrFPS = 0;
	m_tmrFPSCount = 0;
	m_tmrFPSStart = 0;
}

clkTimer::~clkTimer()
{
	shutTimer();
}

void clkTimer::initTimer()
{
	QueryPerformanceFrequency((LARGE_INTEGER*)&m_tmrFrequency);
	m_tmrTicks = 1.0f/((float)m_tmrFrequency);
	QueryPerformanceCounter((LARGE_INTEGER*)&m_tmrStart);
}

void clkTimer::shutTimer()
{

}

void clkTimer::updateTime()
{
	if(m_tmrFirst)
	{
		m_tmrFirst = false;
		updateTime();
	}

	INT64 current = 0;
	INT64 difference = 0;

	QueryPerformanceCounter((LARGE_INTEGER*)&current);
	difference = (current - m_tmrStart);
	m_tmrElapsed = ((float)difference) * m_tmrTicks;
	m_tmrStart = current;
	m_tmrTime += m_tmrElapsed;

	m_tmrFPSCount++;
	if(m_tmrTime >= m_tmrFPSStart+1.0f)
	{
		m_tmrFPS = m_tmrFPSCount;
		m_tmrFPSCount = 0.0f;
		m_tmrFPSStart = m_tmrTime;
	}
}